//
//  Loan_ApplyMainView.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/5.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "Loan_ApplyMainView.h"

@interface Loan_ApplyMainView ()<ShowRightImageViewPeakViewDelegate, UITextFieldDelegate>

@property(nonatomic,assign)float float_recentHeight;//最近高度

@end

@implementation Loan_ApplyMainView



-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self initialize];
    }
    return self;
}

-(void)initialize{
    [self.InstallmentPeriods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(25);
        make.width.mas_offset(@(ScreenWidthMao-50));
        make.top.mas_equalTo(self);
        make.height.mas_offset(@56);
    }];
    [self.repaymentWay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.InstallmentPeriods);
        make.top.mas_equalTo(self.InstallmentPeriods.mas_bottom);
    }];
    [self.loanPurpose mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.InstallmentPeriods);
        make.top.mas_equalTo(self.repaymentWay.mas_bottom);
    }];
    [self.collectionAccount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.InstallmentPeriods);
        make.top.mas_equalTo(self.loanPurpose.mas_bottom);
    }];
    [self.shouldPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.InstallmentPeriods);
        make.top.mas_equalTo(self.collectionAccount.mas_bottom);
    }];
    
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.shouldPay.mas_bottom);
        make.left.mas_equalTo(self.mas_left).offset(ScreenWidthMao/375*150);
        make.width.mas_offset(@52);
        make.height.mas_offset(@16);
    }];
    
    [self.firstPeriodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.tipLabel);
        make.left.mas_equalTo(self.tipLabel.mas_right).offset(3);
        make.right.mas_equalTo(self.mas_right).offset(-12);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = ThemeMaoLineColor;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.shouldPay);
        make.height.mas_offset(@0.5);
        make.top.mas_equalTo(self.tipLabel.mas_bottom).offset(14);
    }];
    
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.repaymentWay);
        make.top.mas_equalTo(self.shouldPay.mas_bottom).offset(60);
        make.height.mas_offset(@44);
    }];
    
}

- (void)showSelectPeakView:(Loan_RightImageView *)view {
    
    [self endEditing:YES];
    if ([self.mainViewDelegate respondsToSelector:@selector(showBankPeakView:)]) {
        [self.mainViewDelegate showBankPeakView:view];
    }
}

- (void)sureBtnAction {
    
    [self endEditing:YES];
    if ([self.mainViewDelegate respondsToSelector:@selector(sureBtnAction)]) {
        [self.mainViewDelegate sureBtnAction];
    }
}


-(Loan_RightImageView *)InstallmentPeriods{
    if (!_InstallmentPeriods) {
        _InstallmentPeriods = [[Loan_RightImageView alloc]init];
        _InstallmentPeriods.titleLabel.text = @"分期期数";
        _InstallmentPeriods.tag = 1;
        _InstallmentPeriods.delegate = self;
        [self addSubview:_InstallmentPeriods];
    }
    return _InstallmentPeriods;
}

-(Loan_RightImageView *)repaymentWay{
    if (!_repaymentWay) {
        _repaymentWay = [[Loan_RightImageView alloc]init];
        _repaymentWay.titleLabel.text = @"分期方式";
        _repaymentWay.tag = 2;
        _repaymentWay.delegate = self;
        [self addSubview:_repaymentWay];
    }
    return _repaymentWay;
}

-(Loan_RightImageView *)loanPurpose{
    if (!_loanPurpose) {
        _loanPurpose = [[Loan_RightImageView alloc]init];
        _loanPurpose.titleLabel.text = @"借款用途";
        _loanPurpose.tag = 3;
        _loanPurpose.delegate = self;
        [self addSubview:_loanPurpose];
    }
    return _loanPurpose;
}

-(Loan_RightImageView *)collectionAccount{
    if (!_collectionAccount) {
        _collectionAccount = [[Loan_RightImageView alloc]init];
        _collectionAccount.titleLabel.text = @"收款账户";
        _collectionAccount.tag = 4;
        _collectionAccount.delegate = self;
        [self addSubview:_collectionAccount];
    }
    return _collectionAccount;

}

-(Loan_RightImageView *)shouldPay{
    if (!_shouldPay) {
        _shouldPay = [[Loan_RightImageView alloc]init];
        _shouldPay.titleLabel.text = @"每期应还";
        _shouldPay.tag = 5;
        _shouldPay.delegate = self;
        _shouldPay.lineImageView.hidden = YES;
        
        _tipLabel = [[UILabel alloc]init];
        _tipLabel.text = @"首期应还";
        _tipLabel.textAlignment = NSTextAlignmentCenter;
        _tipLabel.backgroundColor = ThemeMaoColor;
        _tipLabel.textColor = [UIColor whiteColor];
        _tipLabel.font = [UIFont systemFontOfSize:10];
        _tipLabel.layer.masksToBounds = YES;
        _tipLabel.layer.cornerRadius = 2;
        [self addSubview:_tipLabel];
        
        _firstPeriodLabel = [[UILabel alloc]init];
        _firstPeriodLabel.font = [UIFont systemFontOfSize:13];
        _firstPeriodLabel.text = @"¥416.66(9月11日)";
        _firstPeriodLabel.textColor = HexColor(0x333333);
        [self addSubview:_firstPeriodLabel];
        [self addSubview:_shouldPay];
    }
    return _shouldPay;
    
}

-(UIButton *)sureBtn{
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureBtn setBackgroundImage:[UIImage imageNamed:@"select_btn"] forState:UIControlStateNormal];
        [_sureBtn setTitle:@"确认借款" forState:UIControlStateNormal];
        [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _sureBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_sureBtn setBackgroundColor:HexColor(0xBEA471)];
        _sureBtn.layer.masksToBounds = YES;
        _sureBtn.layer.cornerRadius = 4;
        [self addSubview:_sureBtn];
    }
    return _sureBtn;
}



@end
